#!/bin/sh

rm -rf builds/out-adv-bench
mkdir -p builds/out-adv-bench

bin/cljsc benchmark "{:optimizations :advanced :output-wrapper true :compiler-stats true :verbose true :output-dir \"builds/out-adv-bench\"}" > builds/out-adv-bench/core-advanced-benchmark.js

if [ "$V8_HOME" = "" ]; then
  echo "V8_HOME not set, skipping V8 benchmarks"
else
  echo "Benchmarking with V8"
  "${V8_HOME}/d8" builds/out-adv-bench/core-advanced-benchmark.js
fi

if [ "$SPIDERMONKEY_HOME" = "" ]; then
  echo "SPIDERMONKEY_HOME not set, skipping SpiderMonkey benchmarks"
else
  echo "Benchmarking with SpiderMonkey"
  "${SPIDERMONKEY_HOME}/js" -f builds/out-adv-bench/core-advanced-benchmark.js
fi

if ! hash jsc 2>/dev/null; then
  echo "jsc not on path, skipping JavaScriptCore benchmarks"
else
  echo "Benchmarking with JavaScriptCore"
  jsc -f builds/out-adv-bench/core-advanced-benchmark.js
fi

if [ "$NASHORN_HOME" = "" ]; then
  echo "NASHORN_HOME not set, skipping Nashorn benchmarks"
else
  echo "Benchmarking with Nashorn"
  "${NASHORN_HOME}/jjs" builds/out-adv-bench/core-advanced-benchmark.js
fi

if [ "$CHAKRACORE_HOME" = "" ]; then
  echo "CHAKRACORE_HOME not set, skipping ChakraCore benchmarks"
else
  echo "Benchmarking with ChakraCore"
  "${CHAKRACORE_HOME}/ch" builds/out-adv-bench/core-advanced-benchmark.js
fi

if [ "$GRAALVM_HOME" = "" ]; then
  echo "GRAALVM_HOME not set, skipping GraalVM benchmarks"
else
  echo "Benchmarking with GraalVM"
  "${GRAALVM_HOME}/js" builds/out-adv-bench/core-advanced-benchmark.js
fi
